package com.tjetc.dao.impl;

import com.tjetc.dao.GuestDao;
import com.tjetc.pojo.dto.GuestDTO;
import com.tjetc.pojo.entity.Guest;
import com.tjetc.pojo.vo.GuestIdVO;
import com.tjetc.utils.DruidUtils;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.util.List;

/**
 * @Author: itda
 * @Date: 2024/5/11 19:04
 * @Description: GuestDaoImpl
 */
public class GuestDaoImpl implements GuestDao {
    @Override
    public GuestDTO getById(Long guestId) throws Exception {
        return DruidUtils.r2.query("select g.id,u.id,u.username,u.password,u.email,u.gender,u.phone from guest g,user u where g.user_id=u.id and g.id = ?", new BeanHandler<>(GuestDTO.class), guestId);
    }

    @Override
    public void insert(Long guestId) throws Exception {
        DruidUtils.r1.update(DruidUtils.getConnection(), "insert into guest (user_id) values (?);", guestId);
    }

    @Override
    public GuestIdVO getByUserId(Long userId) throws Exception {
        return DruidUtils.r1.query(DruidUtils.getConnection(),"select id guestId from guest where user_id = ?", new BeanHandler<>(GuestIdVO.class), userId);
    }

    @Override
    public Guest getUserId(Long userId) throws Exception{
        return DruidUtils.r2.query("select * from guest where user_id = ?",new BeanHandler<>(Guest.class),userId);
    }

    @Override
    public void save(Long userId) throws Exception{
        DruidUtils.r1.update(DruidUtils.getConnection(),"insert into guest (user_id) values (?)", userId);
    }

}
